<!DOCTYPE html>
<html>
  <head>
    <title>注册</title>
    <%- include('./head') %>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1>注册</h1>
    <p>
    	用户名: <input type="text" name="username" id="username" value="" />
    </p>
    <p>
    	密<em style="padding-left: 1em;"></em>码: <input type="text" name="password" id="password" value="" />
    </p>
    <p>
    	<button class="btn">注册</button>
    	<a href="/signin" class="loginTo">登录</a>
    </p>
  </body>
  <script type="text/javascript" src="/javascripts/jquery.js"> </script>
  <script type="text/javascript">
  	
	$(".btn").on("click",function(){
		var name = $("#username").val().trim();
		var pwd = $("#password").val().trim();
		$.ajax({
			type:"post",
			url:"/api/user/signup",
			data:{
				name:name,
				password:pwd
			},
			success:function(data){
			
				console.log(data);
				if(data.code == 1){
					window.location.href = '/signin';
				}else{
					alert(data.message);
				}
			},
			error:function(error){
				console.log(error);
			}
		});
	});
  </script>
</html>
